/*****************************************************************************************
   
   Copyright (c) Microsoft Corporation. All rights reserved.

   Use of this code sample is subject to the terms of the Microsoft
   Permissive License, a copy of which should always be distributed with
   this file.  You can also access a copy of this license agreement at:
   http://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx

 ****************************************************************************************/

using System;

namespace GrooveWebServicesV12Helpers.SharepointFiles
{
	/// <summary>
	/// Represents a Groove Sharepoint Files tool.
	/// </summary>
    public class SharepointFilesTool : GrooveWebServicesV12Helpers.Files.FilesTool
    {
        public SharepointFilesTool(GrooveWebServicesV12Helpers.Space i_Space, GrooveToolsWebService.Tool i_Tool) :
			base(i_Space, i_Tool, true)
		{
            //  Make sure we are dealing with a 3.0 or later Forms tool
            if (this.Type != GrooveWebServicesV12Helpers.Shared.GROOVE_SHAREPOINT_FILES_TOOL_SUPPORTED_TYPE)
                throw new System.ArgumentException("Tool is not a Groove 2007 or later Sharepoint Files tool!");
        }

        /// <summary>
        /// Provides initial configuration for the tool
        /// </summary>
        /// <param name="i_DocumentLibraryURL">URL of the SharePoint document library</param>
        /// <param name="i_SynchronizerIdentityURL">IdentityURL of the Groove user who is responsible for synchronizing the tool with the SharePoint document library</param>
        /// <returns>Array of Files</returns>

        public void SetInitialConfiguration(string i_DocumentLibraryURL, string i_SynchronizerIdentityURL)
        {
            //  Get initialized reference to web service
            GrooveFilesWebService.GrooveFilesBase64 FilesWebService = base.GetInitializedFilesWebService(this.Data);

            GrooveFilesWebService.WSSPropertiesDescriptor WSSPropertiesDescriptor = new GrooveFilesWebService.WSSPropertiesDescriptor();
            WSSPropertiesDescriptor.DocumentLibraryURL = i_DocumentLibraryURL;
            WSSPropertiesDescriptor.SynchronizerIdentity = i_SynchronizerIdentityURL;

            System.DateTime BeginDateTime = System.DateTime.Now;

            //  Ask service to set wss properties
            FilesWebService.SetWSSProperties(WSSPropertiesDescriptor);

            if (GrooveWebServicesV12Helpers.Context.TraceEnabled)
            {
                System.TimeSpan TimeSpan = System.DateTime.Now.Subtract(BeginDateTime);
                System.Diagnostics.Debug.WriteLine("FilesWebService::SetWSSProperties, " + TimeSpan.TotalMilliseconds + " ms");
            }
        }

    }
}
